package p2pcdnsim.network;

public class DatagramPacket implements Datagram {

	private static final long UDP_HEADER_SIZE = 16;
	
	private NetworkAddress sourceAddress;
	private NetworkAddress destinationAddress;
	private int sourcedPort;
	private int destinationPort;
	
	private ApplicationMessage message;

	public ApplicationMessage getMessage() {
		return message;
	}


	public void setMessage(ApplicationMessage message) {
		this.message = message;
	}


	public DatagramPacket(NetworkAddress localAddress, int localPort,
			NetworkAddress destinationAddress, int destinationPort) {
		this.sourceAddress = localAddress;
		this.sourcedPort = localPort;
		this.destinationAddress = destinationAddress;
		this.destinationPort = destinationPort;
	}
	
	
	public int getSourcedPort() {
		return sourcedPort;
	}

	@Override
	public NetworkAddress getDestinationAddress() {
		return destinationAddress;
	}

	@Override
	public NetworkAddress getSourceAddress() {
		return sourceAddress;
	}

	@Override
	public long getSize() {
		if(message == null) return UDP_HEADER_SIZE;
		return UDP_HEADER_SIZE + message.getLength();
	}

	public int getDestinationPort() {
		return destinationPort;
	}

}
